package com.top75;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: huangzhigao
 * @Date: 2023/5/16 20:19
 */
public class Code2352 {
    public static int equalPairs(int[][] grid) {
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < grid.length; i++) {
            StringBuilder line = new StringBuilder();
            for (int j = 0; j < grid[i].length; j++) {
                line.append(grid[i][j]).append("-");
            }
            map.put(line.toString(), map.getOrDefault(line.toString(), 0) + 1);
        }

        int res = 0;
        for (int j = 0; j < grid[0].length; j++) {
            StringBuilder column = new StringBuilder();
            for (int i = 0; i < grid.length; i++) {
                column.append(grid[i][j]).append("-");
            }
            if (map.containsKey(column.toString())) {
                res = res + map.get(column.toString());
            }
        }
        return res;
    }


    public static void main(String[] args) {
        int[][] num = {{3, 2, 1}, {1, 7, 6}, {2, 7, 7}};
        System.out.println(equalPairs(num));
    }
}
